"""
    读物文件
"""
import configparser
import json
import os
import yaml

# 此方法结果是 D:\workspace\接口测试\zonghe
def getProjectRoot():
    # 获取此文件的
    current_file_path=os.path.abspath(__file__)
    current_dir_path=os.path.dirname(current_file_path)
    current_project_path=os.path.dirname((current_dir_path))
    return current_project_path

"""
    读取test.ini文件中的section模块下的option的内容
    [env]
    base_url=http://192.168.151.6:8080
"""
def read_config(option,section="env"):
    print("读取test.ini文件")
    ini_file_path = getProjectRoot()+r"\test.ini"
    config=configparser.ConfigParser()
    config.read(ini_file_path)
    return config.get(section,option)

def read_yaml(file_name):
    # 拼接yaml数据文件的路径
    file_path=getProjectRoot()+"\\test_data\\"+file_name
    # 读取yaml数据文件的内容
    with open(file_path,mode='r',encoding="utf-8")as f:
        c=f.read()
    # 文件内容按照yaml格式加载到python中
    return yaml.load(c,Loader=yaml.FullLoader)

if __name__ == '__main__':
    print("get"+getProjectRoot())
    print(read_config("base_url"))
    print(read_config("db_info"))
    db_info=json.loads(read_config("db_info"))
    print(db_info["host"])
    y=read_yaml("register_fail_data.yaml")
    print(y)
    #访问列表中的数据
    for y1 in y:
        print(y1["data"])